package com.hs.server.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hs.server.dto.VehPhotodesDto;
import com.hs.server.dto.Vehicle;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@DS("ajlw_sj")
public interface XbjcMapper {
    @Select("select distinct a.jyxm,a.syrlxdh,a.sjr,lsh,b.lszt,a.jycs,a.jyrq,a.jylsh,a.hpzl,a.hphm,a.clsbdh,a.syr,a.cllx,a.syxz,a.zbzl,a.kssj,a.jssj,a.fdjh,a.clpp1,a.clxh,a.ccdjrq,a.ccrq,a.jylb,a.xszbh,a.rlzl,a.csys,a.pl,a.gl,a.zxxs,a.cwkc,a.cwkk,a.cwkg,a.hxnbcd,a.hxnbkd,a.hxnbgd,a.gbthps,a.zs,a.zj,a.qlj,a.hlj,a.ltgg,a.lts,a.zzl,a.hdzzl,a.hdzk,a.zqyzl,a.qpzk,a.hpzk,a.clyt,a.ytsx,a.clpp2,a.gcjk,a.zzg,a.zzcmc,a.fdjxh,a.zsxzqh from veh_login a left join veh_flow b on a.jylsh=b.jylsh and a.jycs = b.zjcs left join veh_photodes c on b.jylsh = c.jylsh where c.pssj > #{qsrq} and sfdjjc = '0' and yshbj in (0,4)  and zpshbj = 0   order by jssj desc limit #{limit};")//and (b.jylsh = '250710440003N0668065')
    List<Vehicle> getVehicleList(String qsrq, int limit);

    @Select("select jylsh,zpzl from veh_photodes where jylsh = #{jylsh} and zpshbj = 0")
    List<VehPhotodesDto> getPhotoInfoList(String jylsh);

    @Update("update veh_photodes set ZPSHBJ = #{zpshbj} where jylsh = #{jylsh}")
    int updateZpshbj(String jylsh,String zpshbj);

    @Update("update veh_photodes set ZPSHBJ = #{zpshbj} where jylsh = #{jylsh} and zpzl = #{zpzl}")
    Integer updateZpshbjByZpzl(String jylsh,String zpshbj,String zpzl);

    @Select("select ZPSHBJ from veh_photodes where jylsh = #{jylsh} and zpzl = #{zpzl}")
    String getZpshbjByZpzl(String jylsh,String zpzl);

    @Update("update veh_flow set YSHBJ = #{yshbj} where jylsh = #{jylsh}")
    int updateVehFlowYshbj(String jylsh,String yshbj);

    @Select("select jyjgbh from frm_department limit 1")
    String getJyjgbh();

    @Select("select lszt from veh_flow where jylsh = #{jylsh}")
    String getLszt(String jylsh);

    @Select("select count(*) from veh_photodes where jylsh = #{jylsh} and zpshbj = 0")
    int getUnreviewedCount(String jylsh);

    @Update("update veh_flow set yshbj = 0 where yshbj = 4")
    int resetYshbj();

    @Update("update veh_photodes set zpshbj = 0 where zpshbj = 4")
    int resetZPSHBJ();

    @Select("select distinct b.jylsh from veh_flow b where b.yshbj in ('0','4') and b.sfdjjc = '0'  and b.lszt in ('4','5','10') and exists ( select 1 from veh_photodes c where b.jylsh = c.jylsh and c.pssj > #{startTime} ) and not exists ( select 1 from veh_photodes c2 where b.jylsh = c2.jylsh and c2.zpshbj in ('0','4') ) limit 30;")
    List<String> judgeFinish(String startTime);//

    @Select("update veh_aiauditinfo set shjg = #{shjg},btgyy = #{btgyy},ZP=null where jylsh = #{jylsh} and zpzl = #{zpzl}")
    Integer updateShjg(String jylsh,String shjg,String btgyy,String zpzl);

    //SELECT count(*) FROM veh_photodes curr LEFT JOIN veh_photodes prev ON curr.JYLSH = prev.JYLSH AND curr.PSSJ > prev.PSSJ AND prev.ZPZL IN ('0322','0348') AND NOT EXISTS ( SELECT 1 FROM veh_photodes mid WHERE mid.JYLSH = curr.JYLSH AND mid.PSSJ > prev.PSSJ AND mid.PSSJ < curr.PSSJ AND mid.ZPZL IN ('0322','0348') ) WHERE curr.ZPZL IN ('0322','0348') AND TIMESTAMPDIFF(SECOND, prev.PSSJ, curr.PSSJ) > 60 AND curr.JYLSH = '250630440003N0600435';
    int judgeTime(@Param("zpzlList") List<String> zpzlList, @Param("jylsh") String jylsh);
}
